






//
//  SolveMapEvent.m
//  住房条件帅选器
//
//  Created by MB__Lee on 2018/5/20.
//  Copyright © 2018年 MB__Lee. All rights reserved.
//

#import "SolveMapEvent.h"

#import <Masonry.h>

@interface SolveMapEvent()
@property(nonatomic,strong)UIViewController *vc;
@property(nonatomic,strong)UIView *mapView;

@property(nonatomic,strong)UIButton *listBTN; //点击弹出房源列表
@property(nonatomic,strong)BaseListTableview *tableview;

@end


@implementation SolveMapEvent



-(instancetype)initWithViewController:(UIViewController *)vc mapView:(UIView *)mapView{
    if (self  = [super init]) {
        self.vc = vc;
        self.mapView = mapView;
    }
    return  self;
}


-(UIButton *)listBTN{
    if (!_listBTN) {
        _listBTN  = [UIButton buttonWithType:UIButtonTypeCustom];
        _listBTN.frame = CGRectMake(0, 0, 100, 30);
        _listBTN.backgroundColor = [UIColor greenColor];
        [_listBTN addTarget:self action:@selector(listBTNClik:) forControlEvents:UIControlEventTouchUpInside];
        
        [_listBTN mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.right.equalTo(_mapView);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(30);
        }];
    }
    
    return _listBTN;
}
-(void)listBTNClik:(UIButton *)btn{
    [self.tableview  addSubview:_mapView];
    
}
-(BaseListTableview *)tableview{
    if (!_tableview) {
        CGFloat height = 375.0 / 505.0  *_mapView.bounds.size.height;
        _tableview = [[BaseListTableview alloc]initWithFrame:CGRectMake(0, 0, _mapView.bounds.size.width, height) style:UITableViewStylePlain];
        
        
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tableview.bounds.size.width, MBScaleH(44))];
        UIButton *btn  =[UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, MBScale(60), MBScaleH(44));
        [btn setTitle:@"收起" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnDisTableview:) forControlEvents:UIControlEventTouchUpInside];
        
        
        [v addSubview: btn];
        _tableview.tableHeaderView = v;
        
        
        
        
    }
    return _tableview;
}
-(void)btnDisTableview:(UIButton *)btn{
    [self.tableview removeFromSuperview];
}
#pragma mark ---PrivateMethod
-(void)SearchView_showAtMap{
    [self.tableview addSubview:_mapView];
}
-(void)SearchView_hiddenAtMap{
    [self.tableview removeFromSuperview];
}
-(void)SearchView_deleteSource{
    [self.tableview deleteSource];
}
-(void)SearchView_insertSourceFromVC:(NSMutableArray *)mapSource{
    [self.tableview.BaseHouseMut addObjectsFromArray:mapSource];
    [self.tableview reloadData];
}
-(void)SearchView_deleteLastInsertNew:(NSMutableArray *)newSource{
    [self.tableview deleteSource];
    [self.tableview.BaseHouseMut addObjectsFromArray:newSource];
    [self.tableview reloadData];
}



@end
